package test;


import benchmark.Benchmark;
import data.IntegerDataSetGenerator;
import implementation.sort.AbstractSorter;
import implementation.sort.MergeSort.MergeBottomUp;
import implementation.sort.MergeSort.MergeTopDown;

import java.util.ArrayList;
import java.util.Comparator;

public class MergeReport {

    private static Benchmark benchmark;
    private static IntegerDataSetGenerator generator;

    public static void main(String[] args) {
        benchmark = new Benchmark();
        MergeTopDown topDown = new MergeTopDown();
        MergeBottomUp bottomUp = new MergeBottomUp();
        topDown.addSorterListener(benchmark);
        bottomUp.addSorterListener(benchmark);
        generator = new IntegerDataSetGenerator();
        Comparator comparator = generator.getComparator();
        ArrayList<Integer> nList = getNList();

        for (int i = 0; i < nList.size(); i++) {
            int n = nList.get(i);
            System.out.println("N = " + n);
            ArrayList<Integer> randomList = (ArrayList) generator.createRandom(n);

            printReport(topDown, comparator, randomList);
            printReport(bottomUp, comparator, randomList);

        }
    }

    private static void printReport(AbstractSorter sorter, Comparator comparator, ArrayList<Integer> randomList) {
        ArrayList<String> randomListC = (ArrayList) randomList.clone();
        System.out.println("\t" + sorter.getType());

        long t0 = System.currentTimeMillis();
        sorter.sort(comparator, randomListC);
        long tf = System.currentTimeMillis();

        System.out.println("\t\t\tTime: " + (tf - t0));
        System.out.println("\t\t\tComparissons: " + benchmark.getComparisons());
    }

    public static ArrayList<Integer> getNList() {
        ArrayList<Integer> nList = new ArrayList<Integer>();
        nList.add(100);
        nList.add(500);
        nList.add(1000);
        nList.add(2500);
        nList.add(5000);
        return nList;
    }
}
